package badugaserver;
/**
 * @author Wojtek N., Kamil M.
 * @version 0.7
 * Class which defines what is it card.
 */
public class Card implements Comparable<Card>
{
	
	private int rankID, suitID;
	private static final String[] allFullSuits = {null,"heart","spade","diamond","club"};
	private static final String[] allSuits = {null,"h","s","d","c"};
	private static final String[] allFullRanks = {null,"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
	private static final String[] allRanks = {null,"A","2","3","4","5","6","7","8","9","T","J","Q","K"};
	
	/**
	 * Constructor of the class Card.
	 */
	public Card(int rankID, int suitID) throws BadugaExceptions
	{
		if(suitID<1 || suitID>4 || rankID<1 || rankID>13)
		{
			throw new BadugaExceptions(4);
		}
		this.rankID = rankID;
		this.suitID = suitID;
	}
	
	/**
	 * @return rank of the card.
	 */
	public String returnRankAsString(int rankID)
	{
		return allRanks[rankID];
	}
	
	/**
	 * @return suit of the card.
	 */
	public String returnSuitAsString(int suitID)
	{
		return allSuits[suitID];
	}
	
	/**
	 * @return if false : rank + suit of the card (for example: Ah, Td, etc.); else full rank + full suit (for example: Ace of harts, 10 of diamonds, etc.)
	 */
	public String toString(boolean which)
	{
		if(!which)
		{
			return allRanks[rankID] + allSuits[suitID];
		}
		else
		{
			return allFullRanks[rankID] + " of " + allFullSuits[suitID] + " ";
		}
	}
	
	/**
	 * @return if 0 - compared cards are same; else are different.
	 */
	@Override
	public int compareTo(Card card)
	{
		int comparedRank = Integer.compare(this.getRank(), card.getRank());
		int comparedSuit = Integer.compare(this.getSuit(), card.getSuit());
		if (comparedRank != 0)
		{
			return comparedRank;
		}
		else
		{
			return comparedSuit;
		}
	}
	
	/**
	 * @return rankID of the card.
	 */
	public int getRank() 
	{
		return rankID;
	}

	/**
	 * @return suitID of the card.
	 */
	public int getSuit() 
	{
		return suitID;
	}
}
